*** Set relevant working directory
*cd "*********"

use "VCM Results.dta", clear

*** T-Tests (Section 3.1 Control VCM) 
**T-Tests Basic VCM 
ttest GroupEndowment = 0 if Institution == 3 & AgentStrategy == "Utility-Maximizing" 
ttest GroupEndowment = 0 if Institution == 3 & AgentStrategy == "Complex Adaptive" 
ttest GroupEndowment if Institution == 3, by(AgentStrategy)

**** Figure 1: Utility Maximizer Graphs (Experiment 2)
*** 1a Cent Sanction Graph (Utility-Maximizing); includes varying sanctions; legends, titles, and axes modified manually
use "VCM Results.dta", clear
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment if Institution == 1 & AgentStrategy == "Utility-Maximizing" & CentMonitor == .1, by (CentSanction)
gen endowment95plus = GroupEndowment + (SEM * 1.972)
gen endowment95minus = GroupEndowment - (SEM * 1.972)
twoway (connected GroupEndowment CentSanction, mcolor(black) lcolor(black) lwidth(thin)) (rcap endowment95plus endowment95minus CentSanction, yline(224.41)  lcolor(black)) 
** 1b Decent Utility-Maximizing; legends, titles, and axes modified manually
use "VCM Results.dta", clear
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment if Institution == 2 & AgentStrategy == "Utility-Maximizing" , by (MonitorCostProp)
gen endowment95plus = GroupEndowment + (SEM * 1.972)
gen endowment95minus = GroupEndowment - (SEM * 1.972)
twoway (connected GroupEndowment MonitorCostProp, mcolor(black) lcolor(black) lwidth(thin)) (rcap endowment95plus endowment95minus MonitorCostProp, yline(224.41) lcolor(black))
** Experiment 2/Figure 1 Discussion
*** Centralized / VCM Comparisons (Utility Maximizing)
** CentSanction = .1
use "VCM Results.dta", clear
drop if Institution == 2
drop if Institution == 1 & CentMonitor != .1
drop if Institution == 1 & CentSanction != .1
drop if AgentStrategy == "Complex Adaptive"
ttest GroupEndowment, by(Institution)
** CentSanction = .9
use "VCM Results.dta", clear
drop if Institution == 2
drop if Institution == 1 & CentMonitor != .1
drop if Institution == 1 & CentSanction != .9
drop if AgentStrategy == "Complex Adaptive"
ttest GroupEndowment, by(Institution)
*** Decentralized / VCM Comparisons (Utility Maximizing)
** Monitor Penalty = 1 (= 10% of initial endowment)
use "VCM Results.dta", clear
drop if Institution == 1
drop if Institution == 2 & MonitorPenalty != 1
drop if AgentStrategy == "Complex Adaptive"
ttest GroupEndowment, by(Institution)
** Monitor Penalty == 9 (=90% of initial endowment)
use "VCM Results.dta", clear
drop if Institution == 1
drop if Institution == 2 & MonitorPenalty != 9
drop if AgentStrategy == "Complex Adaptive"
ttest GroupEndowment, by(Institution)


*** Figure 2: Complex Adaptive Graphs
*** 2a Cent Sanction Graph (Complex Adaptive); includes varying sanctions; legends, titles, and axes modified manually
use "VCM Results.dta", clear
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment if Institution == 1 & AgentStrategy == "Complex Adaptive" & CentMonitor == .1 , by (CentSanction)
gen endowment95plus = GroupEndowment + (SEM * 1.972)
gen endowment95minus = GroupEndowment - (SEM * 1.972)
twoway (connected GroupEndowment CentSanction, mcolor(black) lcolor(black) lwidth(thin)) (rcap endowment95plus endowment95minus CentSanction, yline(877.92) lcolor(black))
***2b Decent Complex Adaptive; legends, titles, and axes modified manually
use "VCM Results.dta", clear
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment if Institution == 2 & AgentStrategy == "Complex Adaptive" , by (MonitorCostProp)
gen endowment95plus = GroupEndowment + (SEM * 1.972)
gen endowment95minus = GroupEndowment - (SEM * 1.972)
twoway (connected GroupEndowment MonitorCostProp, mcolor(black) lcolor(black) lwidth(thin)) (rcap endowment95plus endowment95minus MonitorCostProp, yline(877.92)  lcolor(black))
*** Centralized / VCM Comparisons (Complex Adaptive)
*** CentSanction = .7
use "VCM Results.dta", clear
drop if Institution == 2
drop if Institution == 1 & CentMonitor != .1
drop if Institution == 1 & CentSanction != .7
drop if AgentStrategy == "Utility-Maximizing"
ttest GroupEndowment, by(Institution)
** CentSanction = .9
use "VCM Results.dta", clear
drop if Institution == 2
drop if Institution == 1 & CentMonitor != .1
drop if Institution == 1 & CentSanction != .9
drop if AgentStrategy == "Utility-Maximizing"
ttest GroupEndowment, by(Institution)
*** Decentralized / VCM Comparisons (Complex Adaptive)
** Monitor Penalty = 1 (10% of iniitial endowment)
use "VCM Results.dta", clear
drop if Institution == 1
drop if Institution == 2 & MonitorPenalty != 1
drop if AgentStrategy == "Utility-Maximizing"
ttest GroupEndowment, by(Institution)
** Monitor Penalty == 9 (90% of initial endowment)
use "VCM Results.dta", clear
drop if Institution == 1
drop if Institution == 2 & MonitorPenalty != 9
drop if AgentStrategy == "Utility-Maximizing"
ttest GroupEndowment, by(Institution)

*** Figure 3
** Sensitivity (Monitoring Assumption Robustness Centralized Institution)
*** Cent Monitoring Graph (Utility-Maximizing); includes varying monitoring
*** 3D Centralized Graphs
** Utility-Maximizing; legends, titles, and axes modified manually
use "VCM Results.dta", clear
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment if Institution == 1 & AgentStrategy == "Utility-Maximizing" , by (CentSanction CentMonitor)
twoway contour GroupEndowment CentSanction CentMonitor, ccuts(0(200)3000) scheme(s1mono)
** Complex Adaptive; legends, titles, and axes modified manually
use "VCM Results.dta", clear
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment if Institution == 1 & AgentStrategy == "Complex Adaptive" , by (CentSanction CentMonitor)
twoway contour GroupEndowment CentSanction CentMonitor, ccuts(0(200)3000) scheme(s1mono)

**** Figure 4 (run varying CentMonitor and MonitorPenalty in Appendix); legends, titles, and axes modified manually
use "VCM Results.dta", clear
drop if Institution == 1 & (CentMonitor != .1 | CentSanction !=.5)
drop if Institution == 2 & MonitorPenalty != 2
label define Institution 1 "Centralized" 2 "Decentralized" 3 "Basic VCM", replace
label define stratlabel 0 "D" 1 "U" 2 "T" 3 "C", replace
label values ModalStrategy stratlabel
graph bar (count) if AgentStrategy == "Complex Adaptive",    over(ModalStrategy) over(Institution) scheme(s1mono)


**** Sensitivity Analyses Working Directory; *** All legends, titles, and axes modified manually
** Laptop


*** Grim Trigger
**** Control VCM 
*** Prep Dataset
use "Grim Trigger No Institution.dta", clear
encode InstitutionType, gen(Institution)
rename meanendowmentsumofparticipa GroupEndowment
rename modesstrategyofparticipants ModelStrat
replace ModelStrat = subinstr(ModelStrat,"[","",.)
replace ModelStrat = subinstr(ModelStrat,"]","",.)
gen MODELSTRAT2 = ModelStrat
replace MODELSTRAT2 = "" if MODELSTRAT2 != "0" & MODELSTRAT2 != "1" & MODELSTRAT2 != "2" & MODELSTRAT2 != "3" 
destring MODELSTRAT2, gen(ModalStrategy)
ttest GroupEndowment = 0
*** Figure A.1 Panel A: Centralized VCM 
** Prep Dataset
use "Grim Trigger Centralized.dta", clear
encode InstitutionType, gen(Institution)
rename meanendowmentsumofparticipa GroupEndowment
rename modesstrategyofparticipants ModelStrat
rename CentralizedMonitoringCapacity CentMonitor
replace ModelStrat = subinstr(ModelStrat,"[","",.)
replace ModelStrat = subinstr(ModelStrat,"]","",.)
gen MODELSTRAT2 = ModelStrat
replace MODELSTRAT2 = "" if MODELSTRAT2 != "0" & MODELSTRAT2 != "1" & MODELSTRAT2 != "2" & MODELSTRAT2 != "3" 
destring MODELSTRAT2, gen(ModalStrategy)
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment if CentMonitor == .1 , by (CentSanction)
gen endowment95plus = GroupEndowment + (SEM * 1.972)
gen endowment95minus = GroupEndowment - (SEM * 1.972)
twoway (connected GroupEndowment CentSanction, mcolor(black) lcolor(black) lwidth(thin)) (rcap endowment95plus endowment95minus CentSanction, yline(576.83) lcolor(black))
***** Figure A.1 Panel B: Decentralized VCM
*** Prep Dataset
use "Grim Trigger Decentralized", clear
encode InstitutionType, gen(Institution)
rename meanendowmentsumofparticipa GroupEndowment
rename modesstrategyofparticipants ModelStrat
gen MonitorCostProp = MonitorPenalty / 10
replace ModelStrat = subinstr(ModelStrat,"[","",.)
replace ModelStrat = subinstr(ModelStrat,"]","",.)
gen MODELSTRAT2 = ModelStrat
replace MODELSTRAT2 = "" if MODELSTRAT2 != "0" & MODELSTRAT2 != "1" & MODELSTRAT2 != "2" & MODELSTRAT2 != "3" 
destring MODELSTRAT2, gen(ModalStrategy)
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment, by (MonitorCostProp)
gen endowment95plus = GroupEndowment + (SEM * 1.972)
gen endowment95minus = GroupEndowment - (SEM * 1.972)
twoway (connected GroupEndowment MonitorCostProp, mcolor(black) lcolor(black) lwidth(thin)) (rcap endowment95plus endowment95minus MonitorCostProp, yline(576.83)  lcolor(black))

*** Figure A.2:  Initial Investment to group account
** No Institution
use "Allocation No Institution", clear
encode InstitutionType, gen(Institution)
rename meanendowmentsumofparticipa GroupEndowment
rename modesstrategyofparticipants ModelStrat
replace ModelStrat = subinstr(ModelStrat,"[","",.)
replace ModelStrat = subinstr(ModelStrat,"]","",.)
gen MODELSTRAT2 = ModelStrat
replace MODELSTRAT2 = "" if MODELSTRAT2 != "0" & MODELSTRAT2 != "1" & MODELSTRAT2 != "2" & MODELSTRAT2 != "3" 
destring MODELSTRAT2, gen(ModalStrategy)
ttest GroupEndowment = 0 if InitialAllocation == .5
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment, by (InitialAllocation)
gen endowment95plus = GroupEndowment + (SEM * 1.972)
gen endowment95minus = GroupEndowment - (SEM * 1.972)
twoway (connected GroupEndowment InitialAllocation, mcolor(black) lcolor(black) lwidth(thin)) (rcap endowment95plus endowment95minus InitialAllocation, yline(877.92)  lcolor(black))

** Figure A.3: Centralized
use "Allocation Centralized", clear
encode InstitutionType, gen(Institution)
rename meanendowmentsumofparticipa GroupEndowment
rename modesstrategyofparticipants ModelStrat
rename CentralizedMonitoringCapacity CentMonitor
replace ModelStrat = subinstr(ModelStrat,"[","",.)
replace ModelStrat = subinstr(ModelStrat,"]","",.)
gen MODELSTRAT2 = ModelStrat
replace MODELSTRAT2 = "" if MODELSTRAT2 != "0" & MODELSTRAT2 != "1" & MODELSTRAT2 != "2" & MODELSTRAT2 != "3" 
destring MODELSTRAT2, gen(ModalStrategy)
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment if CentMonitor == .1, by (InitialAllocation CentSanction)
twoway contour GroupEndowment InitialAllocation CentSanction , ccuts(0(150)3000) scheme(s1mono)

** Figure A.4: Decentralized
use "Allocation Decentralized", clear
encode InstitutionType, gen(Institution)
rename meanendowmentsumofparticipa GroupEndowment
rename modesstrategyofparticipants ModelStrat
gen MonitorCostProp = MonitorPenalty / 10
replace ModelStrat = subinstr(ModelStrat,"[","",.)
replace ModelStrat = subinstr(ModelStrat,"]","",.)
gen MODELSTRAT2 = ModelStrat
replace MODELSTRAT2 = "" if MODELSTRAT2 != "0" & MODELSTRAT2 != "1" & MODELSTRAT2 != "2" & MODELSTRAT2 != "3" 
destring MODELSTRAT2, gen(ModalStrategy)
collapse (mean) GroupEndowment (sem) SEM=GroupEndowment, by (InitialAllocation MonitorCostProp )
twoway contour GroupEndowment InitialAllocation MonitorCostProp , ccuts(0(150)3000) scheme(s1mono)





